package monitor;

import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.jcraft.jsch.SftpProgressMonitor;

import play.mvc.Scope.Session;

/**
 * 上传文件进度监控
 *
 *
 * @version 1.0
 * @since JDK1.7
 * @author yutao
 * @company 上海朝阳永续信息技术有限公司
 * @copyright (c) 2016 SunTime Co'Ltd Inc.All rights reserved.
 * @date 2017年5月5日上午10:39:34
 */
public class UpdateProgressMonitor implements SftpProgressMonitor  {

	private long transfered;
	private String serverip;
	private long fileSize;
	private Map<String, Long> fileSizeMap;
	private static Logger logger = LogManager.getLogger(UpdateProgressMonitor.class);
	
	@Override
	public void init(int op, String src, String dest, long max) {}
	
	public UpdateProgressMonitor(String serverip, Map<String, Long> fileSizeMap, long fileSize) {
		this.serverip = serverip;
		this.fileSize = fileSize;
		fileSizeMap.put(serverip, 0L);
		this.fileSizeMap = fileSizeMap;
	}

	@Override
	public boolean count(long count) {
		transfered += count;
		fileSizeMap.put(serverip, (transfered*100)/fileSize);
		return true;
	}

	@Override
	public void end() {
		logger.debug("-----上传文件结束-----");
	}

}
